<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">砂浆凝结时间试验检测记录表</div>
        <div class="codeText">BGLQ05002F</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>

              <td align="center" style="width: 15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100" style="width: 15%" />%RH
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
            <tr trindex="0">
              <td width="100%" colspan="5">1</td>
              <td width="100%" colspan="5">2</td>
            </tr>
            <tr trindex="1">
              <td colspan="2">加水时间(h:min)</td>
              <td colspan="3">
                <el-time-picker class="hide-icon width100" v-model="form.jiassj1" :picker-options="{ selectableRange: '00:00:00-23:59:00' }" format="HH:mm" value-format="HH:mm" placeholder />
              </td>
              <td colspan="2">加水时间(h:min)</td>
              <td colspan="3">
                <el-time-picker class="hide-icon width100" v-model="form.jiassj2" :picker-options="{ selectableRange: '00:00:00-23:59:00' }" format="HH:mm" value-format="HH:mm" placeholder />
              </td>
            </tr>
            <tr trindex="2">
              <td style="width: 10%">
                <span>测试时间(h:min)</span>
              </td>
              <td style="width: 10%">
                <span>历时t(min)</span>
              </td>
              <td style="width: 10%">
                <span>测针截面积（mm<sup>2</sup>）</span>
              </td>
              <td style="width: 10%">
                <span>贯入压力Np（N）</span>
              </td>
              <td style="width: 10%">
                <span>单位面积贯入阻力（Mpa）</span>
              </td>
              <td style="width: 10%">
                <span>测试时间(h:min)</span>
              </td>
              <td style="width: 10%">
                <span>历时t(min)</span>
              </td>
              <td style="width: 10%">
                <span>测针截面积（mm<sup>2</sup>）</span>
              </td>
              <td style="width: 10%">
                <span>贯入压力Np（N）</span>
              </td>
              <td style="width: 10%">
                <span>单位面积贯入阻力（Mpa）</span>
              </td>
            </tr>
            <tr v-for="(e, index) in list" :key="index">
              <td>
                <el-time-picker class="hide-icon" style="width: 100%" v-model="e.cessj1" :picker-options="{ selectableRange: '00:00:00-23:59:00' }" format="HH:mm" value-format="HH:mm" placeholder />
              </td>
              <td>{{ handlelis1(e) }}</td>
              <td>
                <el-input v-model="e.cezjmj1" @blur="handlegrzl(index, 1)"  @keydown.native="handleKeyDown($event, index, 0)" :ref="`${index}_0`"/>
              </td>
              <td>
                <el-input v-model="e.guanryl1" @blur="handlegrzl(index, 1)"  @keydown.native="handleKeyDown($event, index, 1)" :ref="`${index}_1`"/>
              </td>
              <td>{{ e.danwmjgrzl1 }}</td>
              <!-- <td>{{handlegrzl1(e)}}</td> -->
              <td>
                <el-time-picker class="hide-icon" style="width: 100%" v-model="e.cessj2" :picker-options="{ selectableRange: '00:00:00-23:59:00' }" format="HH:mm" value-format="HH:mm" placeholder />
              </td>
              <td>{{ handlelis2(e) }}</td>
              <td>
                <el-input v-model="e.cezjmj2" @blur="handlegrzl(index, 2)"  @keydown.native="handleKeyDown($event, index, 2)" :ref="`${index}_2`"/>
              </td>
              <td>
<!-- {{`${index}_3`  }} -->
                <el-input v-model="e.guanryl2" @blur="handlegrzl(index, 2)"  @keydown.native="handleKeyDown($event, index, 3)" :ref="`${index}_3`"/>
              </td>
              <td>{{ e.danwmjgrzl2 }}</td>
              <!-- <td>{{handlegrzl2(e)}}</td> -->
            </tr>
            <tr height="30px">
              <td colspan="5" class="echarts-border">
                <span>时间-贯入阻力曲线</span>
                <table-line-log-more-chart
                  :className="'echarts-border'"
                  :chartData="chartData1"
                  :xType="'value'"
                  :xMin="chartData1.xMin"
                  :xMax="chartData1.xMax"
                  :interval="chartData1.interval"
                ></table-line-log-more-chart>
              </td>
              <td colspan="5" class="echarts-border">
                <span>时间-贯入阻力曲线</span>
                <table-line-log-more-chart
                  :className="'echarts-border'"
                  :chartData="chartData2"
                  :xType="'value'"
                  :xMin="chartData2.xMin"
                  :xMax="chartData2.xMax"
                  :interval="chartData2.interval"
                ></table-line-log-more-chart>
              </td>
            </tr>
            <tr>
              <td colspan="2">编号</td>
              <td colspan="4">凝结时间(min)</td>
              <td colspan="4">凝结时间平均值(min)</td>
            </tr>

            <tr>
              <td colspan="2">1</td>
              <td colspan="4">
                <el-input type="Number" v-model="form.ningjsj1"  @keydown.native="handleKeyDown($event, 12, 0)" :ref="'12_0'" ></el-input>
              </td>
              <td colspan="4" rowspan="2">{{ handlenjsjpj() }}</td>
            </tr>
            <tr>
              <td colspan="2">2</td>
              <td colspan="4">
                <el-input type="Number" v-model="form.ningjsj2" @keydown.native="handleKeyDown($event, 13, 0)" :ref="'13_0'" ></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="30px" class="bottom-table">
          <tbody>
            <tr>
              <td>
                <el-input :rows="2" type="textarea" v-model="fjsm" />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType" />
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument" />
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType" />
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType" />
  </div>
</template>

<script>
import { getSjNjsjBsInfo } from "@/api/reportsj/sjNjsjBsInfo";
import decimal from "@/utils/big-decimal";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView.vue";
import TableLineLogMoreChart from "@/views/reportForms/components/TableLineLogMoreChart.vue";

import { handleFocus, handleKeyDown } from "@/views/reportForms/utils";
import { computeBiQualification } from "@/api/sycs/biQualification";
import { orderBy } from "lodash";
export default {
  name: "bhw",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BsJudgeBaseEditView,
    TableLineLogMoreChart
  },
  data() {
    return {
      list: [
        { index: 1, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 2, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 3, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 4, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 5, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 6, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 7, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 8, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 9, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null },
        { index: 10, cessj1: null, lis1: null, cezjmj1: null, guanryl1: null, danwmjgrzl1: null, cessj2: null, lis2: null, cezjmj2: null, guanryl2: null, danwmjgrzl2: null }
      ],
      form: {
        ningjsjpj: undefined,
        ningjsj1: undefined,
        ningjsj2: undefined,
        jiassj1: undefined,
        jiassj2: undefined,
        shiyrq: "2024年03月09日",
        gongcbwyt: "",
        baogbh: "",
        jiancdwmc: "山东路桥集团试验检测中心有限公司泰安高速公路施工总承包项目工地试验室",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "汾阳至石楼高速公路",
        yangpmc: "K39+820-K40+440原地面",
        yangpbh: "JTG/T 3610-2019",
        laiysj: "2022年03月09日",
        yangpsl: "3kg",
        yangpzt: "完好无损"
      },
      twoTableData: {},
      threeTableData: {},
      fjsm: "附加声明：",
      dateText: "2024年05月10日",
      readonly: false,
      chartData1: {
        xName: "时间t（min）",
        yName: "贯入阻力值（MPa）",
        xMin: "auto",
        xMax: "auto",
        interval: 30,
        seriesData: [],
        time: ""
      },
      chartData2: {
        xName: "时间t（min）",
        yName: "贯入阻力值（MPa）",
        xMin: "auto",
        xMax: "auto",
        interval: 30,
        seriesData: [],
        time: ""
      }
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    syType: {
      type: [String, Number],
      default: () => ""
    }
  },
  created() {
    this.getInfo();
  },
  watch: {
    // biaogmd:{
    //   handler:function(newValue,oldValue){
    //     this.handlebgmdpj(newValue);
    //   },
    //   deep:true,
    //   immediate:true,
    // },
  },
  methods: {
    // 获取详情
    getInfo() {
      if (!this.excelId) {
        return;
      }
      getSjNjsjBsInfo(this.excelId).then((response) => {
        this.form = response.data;
        if (this.form.jiassj1) {
          this.form.jiassj1 = this.getHourMin(this.form.jiassj1);
        }
        if (this.form.jiassj2) {
          this.form.jiassj2 = this.getHourMin(this.form.jiassj2);
        }
        if (this.form.detailList) {
          this.list = this.form.detailList;
          this.list.forEach((item) => {
            if (item.cessj1) {
              item.cessj1 = this.getHourMin(item.cessj1);
            }
            if (item.cessj2) {
              item.cessj2 = this.getHourMin(item.cessj2);
            }
          });
          this.setEcharts(1);
          this.setEcharts(2);
        }
      });
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      if (!info || !info.label) {
        return;
      }
      if (!this.form.pandyj) {
        this.form.pandyj = info.label;
      } else {
        if (info && info.label) {
          this.form.pandyj += "、" + info.label;
        }
      }
      // 添加指标 info.list
      let keys = [];
      info.list.forEach((item) => {
       if (this.form.baDetailVos[item.refQualId] && this.form.baDetailVos[item.refQualId].jiancjg) {
          this.form.baDetailVos[item.refQualId].symbolValue = item.symbolValue;
          this.form.baDetailVos[item.refQualId].num1 = item.num1;
          this.form.baDetailVos[item.refQualId].num2 = item.num2;
          keys.push(item.refQualId);
        }
      });
      this.computeDetectionResult(keys);
    },

    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }
      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form.baDetailVos[key].jiancjg
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          this.form.baDetailVos[item.qualId] = { ...item };
        });
      });
    },

    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[info.qualId] = info;
      }
      this.computeDetectionResult([info.qualId]);
    },

    submitForm() {
      this.form.detailList = [];
      this.list.forEach((item) => {
        if (item.cessj1 || item.cezjmj1 || item.guanryl1 || item.cessj2 || item.cezjmj2 || item.guanryl2) {
          let e = {
            cessj1: item.cessj1,
            lis1: item.lis1,
            cezjmj1: item.cezjmj1,
            guanryl1: item.guanryl1,
            danwmjgrzl1: item.danwmjgrzl1,
            cessj2: item.cessj2,
            lis2: item.lis2,
            cezjmj2: item.cezjmj2,
            guanryl2: item.guanryl2,
            danwmjgrzl2: item.danwmjgrzl2
          };
          this.form.detailList.push(e);
        }
      });
      return this.form;
    },
    //获取时分
    getHourMin(datestr) {
      let shij = new Date(datestr);
      let hour = shij.getHours(),
        min = shij.getMinutes();
      return hour.toString() + ":" + min.toString();
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      // this.$set(this.form, 'jiancyj', info.label);
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    //贯入阻力
    handlegrzl(index, type) {
      // c= a/b
      const a = this.list[index]["guanryl" + type];
      const b = this.list[index]["cezjmj" + type];
      let c = null;
      if (a && b) {
        c = decimal.divide(a, b);
      }
      this.list[index]["danwmjgrzl" + type] = c;

      this.setEcharts(type);
    },
    handlenjsjpj() {
      if (this.form.ningjsj1 && this.form.ningjsj2) {
        this.form.ningjsjpj = (parseInt(this.form.ningjsj1) + parseInt(this.form.ningjsj2)) / 2;
      } else {
        this.form.ningjsjpj = undefined;
      }
      return this.form.ningjsjpj;
    },
    //历时1（min）
    handlelis1(e) {
      if (e.cessj1 && this.form.jiassj1) {
        let cessj = e.cessj1.split(":"),
          jiassj = this.form.jiassj1.split(":");
        let cssjmin = parseInt(cessj[0]) * 60 + parseInt(cessj[1]);
        let jssjmin = parseInt(jiassj[0]) * 60 + parseInt(jiassj[1]);
        e.lis1 = cssjmin - jssjmin;
      } else {
        e.lis1 = undefined;
      }
      return e.lis1;
    },
    //历时2（min）
    handlelis2(e) {
      if (e.cessj2 && this.form.jiassj2) {
        let cessj = e.cessj2.split(":"),
          jiassj = this.form.jiassj2.split(":");
        let cssjmin = parseInt(cessj[0]) * 60 + parseInt(cessj[1]);
        let jssjmin = parseInt(jiassj[0]) * 60 + parseInt(jiassj[1]);
        e.lis2 = cssjmin - jssjmin;
      } else {
        e.lis2 = undefined;
      }
      return e.lis2;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    hntzhonglei() {},

    // 绘制图表
    setEcharts(index) {
      if (!this.list || this.list.length <= 0) {
        return;
      }
      const detailList = this.list;
      let data1 = [];
      let data2 = [];
      let list = [];
      detailList.forEach((item) => {
        if (item["lis" + index] && item["danwmjgrzl" + index]) {
          list.push({ lis: Number(item["lis" + index]), danwmjgrzl: Number(item["danwmjgrzl" + index]) });
        }
      });
      const array = orderBy(list, ["lis"]);
      let xMin = "auto";
      array.forEach((item, i) => {
        if (i == 0) {
          xMin = item.lis;
        }
        data1.push([item.lis, item.danwmjgrzl]);
        data2.push([item.lis, 0.5]);
      });

      const chart1 = {
        data: data1,
        connectNulls: true,
        smooth: false,
        type: "line"
      };
      const chart2 = {
        data: data2,
        connectNulls: true,
        smooth: false,
        type: "line"
      };

      this["chartData" + index].seriesData = [chart1, chart2];
      this["chartData" + index].time = new Date().getTime();
      this["chartData" + index].xMin = xMin;
      this["chartData" + index].xMax = xMin + array.length * 30;
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]?.length) {
        this.$refs[ref][0].focus();
      } else if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped lang="scss">
.echarts-border {
  width: calc(210mm - 40mm - 8px) / 2;
  height: 176px;
  padding: 2px !important;
  background-color: #ffffff !important;
}
</style>
